package com.ruipengkj.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ruipengkj.bean.TBillDetailDes;
import com.ruipengkj.commons.base.query.BaseQuery;
import com.ruipengkj.commons.base.query.PageModel;
import com.ruipengkj.dao.TBillDetailDesDao;
import com.ruipengkj.service.TBillDetailDesService;
@Service
public class TBillDetailDesServiceImpl implements TBillDetailDesService {

	@Resource
	private TBillDetailDesDao TBillDetailDesDao;//DAO层
	
	//根据条件查询
	@Override
	public List<TBillDetailDes> findService(TBillDetailDes entity) throws Exception {
		String hql = "select o from TBillDetailDes o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(entity.getTBillDetail()!=null&&!entity.getTBillDetail().getDetailID().equals("")){
				whereHQL.append("TBillDetail=?").append(BaseQuery.AND);
				param.add(entity.getTBillDetail());
			}
//			if(entity.getBillType()!=0){
//				whereHQL.append("BillType").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getBillType()+"%");
//			}
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TBillDetailDesDao.findDao(hql, whereHQL.toString(), param, orderby);
	}
//	//根据条件删除
//	@Override
//	public boolean deleteService(TBillDetailDes entity) throws Exception {
//		String hql = "select o from TBillDetail o";
//		StringBuffer whereHQL = new StringBuffer();
//		List<Object> param = new ArrayList<Object>();
//		if (entity != null) {
//			if(entity.getBillType()!=0){
//				whereHQL.append("BillType").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getBillType()+"%");
//			}
//			if(entity.getBillID()!=null&&!entity.getBillID().equals("")){
//				whereHQL.append("BillID").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getBillID()+"%");
//			}
//			if(entity.getCommodityID()!=null&&!entity.getCommodityID().equals("")){
//				whereHQL.append("CommodityID").append(BaseQuery.LIKE).append("?").append(BaseQuery.AND);
//				param.add("%"+entity.getCommodityID()+"%");
//			}
//			if(whereHQL.length()>4)
//				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
//		}
//		List<TBillDetailDes> list=TBillDetailDesDao.findDao(hql, whereHQL.toString(), param, null);
//		if(list!=null&&list.size()!=0){
//			for(int i = list.size()-1; i >= 0 ; --i) {
//				TBillDetailDes com=list.get(i);
//				if(com!=null){
//					TBillDetailDesDao.deleteDao(com.getDetailID());
//				}
//			}
//			return true;
//		}
//		return false;
//	}
		
	
	//根据ID翻页查询
	@Override
	public PageModel<TBillDetailDes> getScrollService(int firstResult,
			int maxResult, TBillDetailDes entity) throws Exception {
		String hql = "select o from TBillDetailDes o";
		StringBuffer whereHQL = new StringBuffer();
		List<Object> param = new ArrayList<Object>();
		if (entity != null) {
			if(whereHQL.length()>4)
				whereHQL.delete(whereHQL.length()-5, whereHQL.length());
		}
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return TBillDetailDesDao.getScrollDao(hql, whereHQL.toString(), param, firstResult, maxResult, orderby);
	}

	//修改
	@Override
	public void modifyService(TBillDetailDes entity) throws Exception {
		TBillDetailDesDao.modifyDao(entity);
		
	}
	//添加
	@Override
	public void saveService(TBillDetailDes entity) throws Exception {
		TBillDetailDesDao.saveDao(entity);
	}

	//根据ID删除
	@Override
	public void deleteService(String id) throws Exception {
		TBillDetailDesDao.deleteDao(id);
		
	}
	//根据ID查询
	@Override
	public TBillDetailDes getByIdService(String id) throws Exception {
		return TBillDetailDesDao.getByIdDao(id);
	}
	//添加或修改
	@Override
	public void saveOrUpdateService(TBillDetailDes entity) throws Exception {
		TBillDetailDesDao.saveOrUpdateDao(entity);
	}
	//添加返回ID
	@Override
	public Serializable saveRetService(TBillDetailDes entity) throws Exception {
		return TBillDetailDesDao.saveRetDao(entity);
	}
	public TBillDetailDesDao gettBillDetailDao() {
		return TBillDetailDesDao;
	}

	public void settBillDetailDao(TBillDetailDesDao TBillDetailDesDao) {
		this.TBillDetailDesDao = TBillDetailDesDao;
	}

}
